package com.example.su_shi_tan_mine.child

import android.os.Bundle
import android.view.View
import androidx.appcompat.widget.Toolbar
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.alibaba.fastjson.JSON
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemChildClickListener
import com.example.su_shi_tan_bas_lib.adapter.JssBaseViewHolder
import com.example.su_shi_tan_bas_lib.adapter.multi22.JssBaseMultiAdapter
import com.example.su_shi_tan_bas_lib.base.BaseFragmentEx
import com.example.su_shi_tan_bas_lib.base.MultiListFragment
import com.example.su_shi_tan_bas_lib.base.SimpleListFragment
import com.example.su_shi_tan_bas_lib.bean.CommonBean
import com.example.su_shi_tan_bas_lib.networking.RestClient
import com.example.su_shi_tan_core.arouter.MineARouter
import com.example.su_shi_tan_core.bean.AddDeliveryInfoHistoryBean
import com.example.su_shi_tan_core.extentions.startNavigation
import com.example.su_shi_tan_mine.R
import com.example.su_shi_tan_mine.arouter.SubPageARouter
import com.example.su_shi_tan_mine.child.bean.PayingWayListBean
import com.example.su_shi_tan_mine.child.provider.PayingWayListALiPayProvider
import com.example.su_shi_tan_mine.child.provider.PayingWayListBankPayProvider
import com.example.su_shi_tan_mine.child.provider.PayingWayListWeiChatProvider
import com.google.android.material.button.MaterialButton
import ikidou.reflect.TypeBuilder
import java.lang.reflect.Type

@Route(path = MineARouter.PAYING_WAY_LIST)
class PayingWayListFragment : MultiListFragment<PayingWayListBean>(), OnItemChildClickListener {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        isAddDividerItemDecoration=false
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        view.setBackgroundResource(R.color.bg_color)
        mHeader?.removeAllViews()
        addHeader(R.layout.comment_header_layout)
        val mToolbar: Toolbar? = mHeader?.findViewById(R.id.mToolbar)
        mToolbar?.title = "收款信息"
        mToolbar?.setNavigationOnClickListener { onBackPressedSupport() }
        mFooter?.removeAllViews()
        addFooter(R.layout.paying_way_list_fragment_footer)
        val interAdd: MaterialButton? = mFooter?.findViewById(R.id.interAdd)
        interAdd?.setOnClickListener {
            ARouter.getInstance()
                .build(MineARouter.ADD_PAYING_WAY)
                .startNavigation(this)
        }
//        mAdapter?.addChildClickViewIds(R.id.aliPayCode,R.id.wxCode)
//        mAdapter?.setOnItemChildClickListener(this)
    }


    override fun netRequest() {

        RestClient.builder()
            .params("page",pageIndex)
            .params("limit",20)

            .url(R.string.queryMyPayment)
            .success {
                parseDate(it)
            }.error { _, _ ->
                onFailed()
            }.failure { onFailed() }
            .build().get()
    }


    override fun parseDate(data: String?) {
//        super.parseDate(data)
        val mArray = JSON.parseArray(data, PayingWayListBean::class.java)
        loadListDate(mArray)
    }

    override fun addOnListItemProvider(mAdapter: JssBaseMultiAdapter<PayingWayListBean?>?) {
        mAdapter?.addItemProvider(PayingWayListWeiChatProvider())
        mAdapter?.addItemProvider(PayingWayListBankPayProvider())
        mAdapter?.addItemProvider(PayingWayListALiPayProvider())
    }

    override val listType: Type = TypeBuilder.newInstance(CommonBean::class.java)
        .beginSubType(List::class.java)
        .addTypeParam(PayingWayListBean::class.java).endSubType().build()

    override fun onItemChildClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {

    }
}